package com.lion.seaman.common.tools;

import java.io.*;
import java.nio.charset.Charset;

public class IOTools {

	public static InputStream string2InputStream(String str, Charset charset) {
		InputStream in = null;
		try {
			in = new ByteArrayInputStream(str.getBytes(charset.name()));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return in;
	}

	public static String inputStream2String(InputStream is) throws IOException {
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		int i = -1;
		while ((i = is.read()) != -1) {
			baos.write(i);
		}
		return baos.toString();
	}
}
